{ include("common.asl") }

!init.
		
+newKnowledgeRequest(ReqID) : ReqID > -1 <-
	!documentsRetrieving(ReqID).
	//!conceptsRetrieving(ReqID);
	//!retrievingAditionalRequest(ReqID).

+!documentsRetrieving(ReqID): ReqID > -1 <-
	.println("Buscando documento....");
	areThereDocumentRequests(ReqID).
	
//-!documentsRetrieving(ReqID)[error(E),error_msg(Msg),code(Cmd),code_src(Src),code_line(Line)]   <- .print("Failed to start due to: ",Msg," (",E,"). Command: ",Cmd, " on ",Src,":", Line).

+getRequiredDocument(ReqId,Document,Dominio): ReqId > -1 <-
	.println(ReqId);
	.println(Document);
	.println(Dominio);
	//Preguntar a Work si dominio esta activo
	makeArtifact("proxy1", "cartagows.WSInterface", ["../../../data/timeprovider.wsdl"], ProxyID);
	Msg = "<tns:GetDayRequest xmlns:tns='http://example.com/timeprovider.wsdl'><tns:day>DIA</tns:day></tns:GetDayRequest>";
	requestOp("GetDay", Msg, Res, ResID)[artifact_id(ProxyID)];
	cartago.invoke_obj(Res,getBody,MsgBody);
	cartago.invoke_obj(XMLManager,buildElementFromString(MsgBody),Elem);
	cartago.invoke_obj(XMLManager,getElementValue("TradeDay","day", Elem), Value);
	.print("Day: ",Value);
	!documentsRetrieving(ReqId).
/*	
+!documentsRetrieving(ReqID): not areThereDocumentRequests(ReqID) <-
	.println("A");
	true.
*/
/*	
+!conceptsRetrieving(ReqID): true <-
	.println("B");
	.println(ReqID).
	
+!retrievingAditionalRequest(ReqID): true <-
	.println("C");
	.println(ReqID).
*/	
-!init[error(E),error_msg(Msg),code(Cmd),code_src(Src),code_line(Line)]   <- .print("Failed to start due to: ",Msg," (",E,"). Command: ",Cmd, " on ",Src,":", Line).
+!init
	<- 
	.wait(1000);//Espera un segundo para no tratar de unirse al workspace antes de que se cree TODO
	println;
  	.my_name(Me);
  	println("--- Supply Coordinator Agent ---");
  	println(Me);	  
  	println;
	joinWorkspace("integrationWorkspace",_);
	focusWhenAvailable("KnowledgeSuppling").
/*
+!init
   <- println;
	  .my_name(Me);
      println("--- Knowledge Coordinator Agent ---");
      println(Me);	  
	  println;
      createWorkspace("integrationWorkspace");
      joinWorkspace("integrationWorkspace",_);
      //!create_organisational_artifacts;
      !create_artifacts.
      */


      
